/*
 *所有关于Bus_合同分拆类的业务代码应在此处编写
*可使用repository.调用常用方法，获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*Bus_合同分拆Service对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using VOL.Core.BaseProvider;
using VOL.Core.Extensions.AutofacManager;
using VOL.Entity.DomainModels;
using System.Linq;
using VOL.Core.Utilities;
using System.Linq.Expressions;
using VOL.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using VOL.Order.IRepositories;
using System.Collections.Generic;
using VOL.Core.ManageUser;
using VOL.Order.Repositories;
using System.ComponentModel.DataAnnotations;
using System;
using VOL.Core.DBManager;
using VOL.Entity.dtomodel;

namespace VOL.Order.Services
{
    public partial class Bus_合同分拆Service
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly IBus_合同分拆Repository _repository;//访问数据库
        private readonly IDic_班组字典Repository _dic班组字典Repository;

        [ActivatorUtilitiesConstructor]
        public Bus_合同分拆Service(
            IBus_合同分拆Repository dbRepository,
            IHttpContextAccessor httpContextAccessor,
            IDic_班组字典Repository dic班组字典Repository
            )
        : base(dbRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            _repository = dbRepository;
            _dic班组字典Repository = dic班组字典Repository;
            //多租户会用到这init代码，其他情况可以不用
            //base.Init(dbRepository);
        }

        public List<Bus_合同分拆> GetWaiBaoBanZuBaoGongList(Bus_合同分拆 bus)
        {
            string 班组长 = UserContext.Current.UserName;

            var dic = _dic班组字典Repository.FindFirst(it => it.组长 == 班组长);

            if (dic != null)
            {
              List<Bus_合同分拆> bus_合同分拆 = _repository.Find(it => it.班组 == dic.班组 
                                                                        && (it.分拆状态 == "已派工" || it.分拆状态 == "已报工")
                                                                        && it.工期类型 == bus.工期类型).ToList();
                return bus_合同分拆;
            }
            else
            {
                VOL.Core.Services.Logger.Info($"2根据自己班组获取班组任务,报错:没有找到班组");
                //throw new Exception("没有找到班组");
                return null;
            }
        }
    }
}
